package io.gitee.zhangbinhub.admin.resource.server.nami.client

import io.gitee.zhangbinhub.admin.common.api.CommonPath
import io.gitee.zhangbinhub.admin.common.api.OauthApi
import io.gitee.zhangbinhub.admin.common.vo.InnerInfoVo
import io.gitee.zhangbinhub.admin.resource.server.vo.*
import org.noear.nami.annotation.NamiClient
import org.noear.solon.annotation.Body
import org.noear.solon.annotation.Mapping
import org.noear.solon.annotation.Param
import org.noear.solon.annotation.Path
import org.noear.solon.core.handle.MethodType
import org.noear.solon.core.util.MimeType

/**
 * @since JDK 11
 */
@NamiClient(name = "oauth-server")
interface CommonOauthServer {
    @Mapping(
        method = [MethodType.GET],
        value = OauthApi.basePath + OauthApi.token,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun applyToken(@Param paramMap: MutableMap<String, Any>): String

    /**
     * 获取应用配置信息
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.innerBasePath + OauthApi.appInfo,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun appInfo(@Param(name = "access_token") token: String): ApplicationVo

    /**
     * 获取所属机构及其所有子机构列表（所属机构）
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.innerBasePath + OauthApi.currAndAllChildrenOrg,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun currAndAllChildrenForOrg(): List<OrganizationVo>

    /**
     * 获取所属机构及其所有子机构列表（管理机构）
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.innerBasePath + OauthApi.currAndAllChildrenMngOrg,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun currAndAllChildrenForMngOrg(): List<OrganizationVo>

    /**
     * 获取所属机构及其所有子机构列表（所有机构）
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.innerBasePath + OauthApi.currAndAllChildrenAllOrg,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun currAndAllChildrenForAllOrg(): List<OrganizationVo>

    /**
     * 获取用户详细信息
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.innerBasePath + OauthApi.currUser,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun userInfo(@Param(name = "access_token") token: String): UserVo?

    /**
     * 获取用户详细信息
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.innerBasePath + OauthApi.currUser,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun userInfo(): UserVo?

    @Mapping(
        method = [MethodType.PATCH],
        value = CommonPath.openInnerBasePath + OauthApi.disableUser + "/{loginNo}",
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun disableUser(@Path(name = "loginNo") loginNo: String): InnerInfoVo

    /**
     * 获取用户列表
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.innerBasePath + OauthApi.userList,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun findUserListInCurrOrg(@Param(name = "rolecode") roleCode: String): List<UserVo>

    /**
     * 获取用户列表
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.innerBasePath + OauthApi.userList,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun findUserListByOrgLevelByCurrUser(
        @Param(name = "orgLevel") orgLevel: String,
        @Param(name = "roleCode") roleCode: String
    ): List<UserVo>

    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + OauthApi.userConfig + "/{userId}",
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun findUserById(@Path(name = "userId") userId: String): UserVo

    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + OauthApi.userConfig,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun findUserByLoginNo(@Param(name = "loginNo") loginNo: String): UserVo

    /**
     * 获取用户列表
     */
    @Mapping(
        method = [MethodType.POST],
        value = CommonPath.openInnerBasePath + OauthApi.userList,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun findUserList(@Body idList: List<String>): List<UserVo>

    /**
     * 获取用户列表
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + OauthApi.userList,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun findUserList(): List<UserVo>

    /**
     * 获取用户列表
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + OauthApi.userList,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun findUserList(
        @Param(name = "orgCode") orgCode: String,
        @Param(name = "roleCode") roleCode: String
    ): List<UserVo>

    /**
     * 获取用户列表
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + OauthApi.userList,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun findUserList(@Param(name = "roleCode") roleCode: String): List<UserVo>

    /**
     * 获取用户列表
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + OauthApi.userList,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun findUserList(
        @Param(name = "loginNo") loginNo: String,
        @Param(name = "orgLevel") orgLevel: String,
        @Param(name = "roleCode") roleCode: String
    ): List<UserVo>

    /**
     * 获取运行参数
     * 参数为空或调用异常均返回默认值的 RuntimeConfigVo 对象
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + OauthApi.runtime + "/{name}",
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun findRuntimeConfigByName(@Path(name = "name") name: String): RuntimeConfigVo

    /**
     * 获取运行参数
     * 参数为空或调用异常均返回默认值的 RuntimeConfigVo 对象
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + OauthApi.runtime,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun findRuntimeConfigMap(): Map<String, RuntimeConfigVo>

    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + OauthApi.orgConfig + "/{orgId}",
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun findOrgById(@Path(name = "orgId") orgId: String): OrganizationVo

    /**
     * 获取所有机构列表
     */
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + OauthApi.orgConfig,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun orgList(): List<OrganizationVo>

    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + OauthApi.roleConfig + "/{roleId}",
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun findRoleById(@Path(name = "roleId") roleId: String): RoleVo

    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + OauthApi.roleConfig,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun roleList(): List<RoleVo>

}